package com.hjc.demo.netty.client;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.EventExecutorGroup;

public class ClientHandler extends SimpleChannelInboundHandler {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf bb = (ByteBuf)msg;
        byte[] respByte = new byte[bb.readableBytes()];
        bb.readBytes(respByte);
        String respStr = new String(respByte);
        System.err.println("client--收到响应：" + respStr);

        ctx.channel().writeAndFlush(Unpooled.copiedBuffer("hello netty".getBytes()));
//      Thread.sleep(300);
//      cf.channel
    }
}
